package richrail;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import richrail.domain.Garage;
import richrail.tools.CommandParser;
import richrail.view.MainPanel;

public class RichRailApp {
	
	Garage garage;
	MainPanel mainPanel;
	
	public RichRailApp() {
		this.garage = new Garage();
		this.mainPanel = new MainPanel(this);
		this.mainPanel.setVisible(true);
		CommandParser.getInstance().setApp(this);
	}
	
	/**
	 * 
	 * @return The garage that contains all trains and wagons
	 */
	public Garage getGarage() {
		return this.garage;
	}	
	
	public static void main(String[] args) {
		RichRailApp app = new RichRailApp();
		
		String string = "";
		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(input);

		try
		{	
			while(true) {
				System.out.print("command: ");
				string = reader.readLine();
				if(string.equals("exit")) {
					break;
				} 
				else if(string.equals("show")) {
					System.out.println("\n"+app.getGarage());
				}				
				else {
					CommandParser.getInstance().parseCommand(string);
				}				
			}
		}
		catch(Exception e){}		
	}

}
